package parser;

import java.util.HashMap;

/**
 * Represents a node in an Abstract Syntax Tree
 * Each node must have an execute method that will call
 * its children.  Extend this class to implement different node types
 * @author greg
 *
 */
abstract public class AstNode {
	protected AstNode lchild;
	protected AstNode rchild;
	private AstNode parent;
	public Object execute(HashMap<String, Object> memory) {
		Object lval = null;
		Object rval = null;
		if(getLchild()!=null)
			lval = lchild.execute(memory);
		if(getRchild()!=null)
			rval = rchild.execute(memory);
		
			return this.executeNode(memory, lval, rval);
		
	}
	
	protected abstract Object executeNode(HashMap<String, Object> memory, Object lval, Object rval);

	public AstNode getLchild() {
		return lchild;
	}

	public void setLchild(AstNode lchild) {
		this.lchild = lchild;
	}

	public AstNode getRchild() {
		return rchild;
	}

	public void setRchild(AstNode rchild) {
		this.rchild = rchild;
	}

	public void setParent(AstNode parent) {
		this.parent = parent;
	}

	public AstNode getParent() {
		return parent;
	}
}
